<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

        <input type="password">
        <button>显示密码</button>

        <script>
            let input = document.querySelector('input');
            let button = document.querySelector('button');

            button.onclick = function (){
                if(input.type == 'text') {
                    input.type = 'password';
                    button.innerHTML = '显示密码';
                }else if(input.type == 'password') {
                    input.type = 'text';
                    button.innerHTML = '隐藏密码'
                }
            }
        </script>   

</body>
</html>